﻿#define USE_SLIMDX
//#define USE_XNA

#region Dependencies

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Runtime.InteropServices;
using System.Reflection;
using System.Threading;
using System.Windows.Forms;

using XNA = Microsoft.Xna.Framework;
using SDX = SlimDX;
using SysDrawing = System.Drawing;
using PhysX = StillDesign.PhysX;
using BEPU = BEPUphysics;

#if USE_SLIMDX
using SlimDX;
using SlimDX.Direct3D10;
using SlimDX.DirectInput;
using SlimDX.DirectSound;
using SlimDX.DirectWrite;
using SlimDX.DXGI;
using SlimDX.Multimedia;
using SlimDX.Windows;
using SlimDX.X3DAudio;
using SlimDX.XACT3;
using SlimDX.XAPO;
using SlimDX.XAudio2;
#endif

#if USE_XNA
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Design;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

using Xen2D;
using XenAspects;
using XenGameBase;
#endif

#endregion // Dependencies

using Blackrain;
using Blackrain.Core;
using Blackrain.Core.Content;
using Blackrain.Native.Win32;
using Blackrain.Core.Windows;

namespace Blackrain
{
    public static class BlackrainEngine
    {
        private static ContentManager contentManager = null;
        //private static SceneManager sceneManager = null;
        //private static LayerManager layerManager = null;
        //private static NetworkManager netManager = null;
        //private static PhysicsManager physicsManager = null;
        //private static EntityManager entityManager = null;
        //private static RenderManager renderManager = null;
        //private static UIManager uiManager = null;
        //private static GameWindowManager gameWindowManager = null;

        private static GameWindow gameWindow = null;

        private static bool isRunning = false;
        private static bool isActive = true;

        private static bool appIdle
        {
            get
            {
                Win32Message.Message msg;
                return !Win32Message.PeekMessage( out msg, IntPtr.Zero, 0, 0, 0 );
            }
        }

        public static GameWindow GetRenderWindow()
        {
            return gameWindow;
        }

        public static void Init( string[] CommandArgs )
        {
            // engine init

            gameWindow = new GameWindow();

            LoadConfigurations();
        }

        public static void LoadConfigurations( )
        {
            //configmanager initialization
        }

        public static void LoadContent()
        {
            // contentmanager initialization

            contentManager.Load( );
        }

        public static void Render()
        {
            // render initialization
        }

        public static void Update()
        {
            while( isRunning )
            {
                Render();
                Application.DoEvents(); // handle pending window messages
            }
        }

        private static void Loop()
        {
            Application.Idle += new EventHandler( OnApplicationIdle );
        }

        private static void OnApplicationIdle( object sender, EventArgs e )
        {
            while( appIdle )
            {
                Render();
            }
        }
    }
}
